﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Zaretto.PasswordGenerator.ReadablePasswordUnitTests
{
    /// <summary>
    /// unit tests for password creation. very simple as not much to test really.
    /// Richard Hazrrison : http://chateau-logic.com http://zaretto.com
    /// </summary>
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestPassPhrases()
        {
            var p1 = Zaretto.PasswordGenerator.Creator.GeneratePhrase(12);
            var p2 = Zaretto.PasswordGenerator.Creator.GeneratePhrase(12);
            Assert.AreNotEqual(p1, p2);
        }
        
        /// <summary>
        /// ensure that the seeding method works to produce the same twice.
        /// </summary>
        /// <remarks>
        /// depends on the underlying random number generator doing this also
        /// </remarks>
        [TestMethod]
        public void TestSeeding()
        {
            Zaretto.PasswordGenerator.Creator.SetSeed(0xdead00f);

            var p1 = Zaretto.PasswordGenerator.Creator.GeneratePhrase(12);
            var p2 = Zaretto.PasswordGenerator.Creator.GeneratePhrase(12);

            var p1_1 = Zaretto.PasswordGenerator.Creator.GeneratePhrase(12);
            var p2_1 = Zaretto.PasswordGenerator.Creator.GeneratePhrase(12);

            Assert.AreNotEqual(p1, p2);
            Assert.AreNotEqual(p1, p1_1);
            Assert.AreNotEqual(p2, p2_1);

            Zaretto.PasswordGenerator.Creator.SetSeed(0xdead00f);
            p1_1 = Zaretto.PasswordGenerator.Creator.GeneratePhrase(12);
            p2_1 = Zaretto.PasswordGenerator.Creator.GeneratePhrase(12);
            Assert.AreEqual(p1, p1_1);
            Assert.AreEqual(p2, p2_1);
            
        }

        [TestMethod]
        public void TestPasswords()
        {
            var p1 = Zaretto.PasswordGenerator.Creator.Generate(12);
            Assert.IsTrue(p1.Length == 12);
            var p2 = Zaretto.PasswordGenerator.Creator.Generate(12);
            Assert.IsTrue(p2.Length == 12);
            Assert.AreNotEqual(p1, p2);
        }
    }
}
